<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商品上架管理列表')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>产品ID：</label>
                                <input type="number" name="productId"/>
                            </li>
                            <li>
                                <label>产品名称：</label>
                                <select name="productName"  class="form-control">
                                    <option value="">所有</option>
                                    <option  th:each="item:${productList}" th:text="${item.name}" th:value="${item.name}"></option>
                                </select>
                            </li>
<!--                            <li>-->
<!--                                <label>：</label>-->
<!--                                <input type="text" name="sceneIds"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>：</label>-->
<!--                                <input type="text" name="clientTypes"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>：</label>-->
<!--                                <input type="text" name="showStartTime"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>：</label>-->
<!--                                <input type="text" name="showEndTime"/>-->
<!--                            </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="product:push:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
<!--                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="product:push:edit">-->
<!--                    <i class="fa fa-edit"></i> 修改-->
<!--                </a>-->
<!--                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="product:push:remove">-->
<!--                    <i class="fa fa-remove"></i> 删除-->
<!--                </a>-->
<!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="product:push:export">-->
<!--                    <i class="fa fa-download"></i> 导出-->
<!--                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('product:push:edit')}]];
        var removeFlag = [[${@permission.hasPermi('product:push:remove')}]];
        var prefix = ctx + "product/push";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "商品上架管理",
                showHeader: true,
                rowStyle: function(row, index) {   // 动态修改行的颜色
                    // 注意：即使不改变颜色，也得返回 '' ，否则会报错。
                    var result = '';
                    if (row.status == 1){
                        result = {css:{"background-color":"rgba(163,231,151,0.5)"}};
                    }
                    return result;
                },
                columns: [
                //     {
                //     checkbox: true
                // },
                {
                    field: 'id',
                    title: '',
                    visible: false,
                },
                // {
                //     field: 'productId',
                //     title: '产品ID'
                // },
                // {
                //     field: 'productName',
                //     title: '产品名称'
                // },
                {
                        field: 'productName',
                        title: '产品名称',
                        formatter: function (value, row){
                            return row.productName + '[' + row.productId + ']'
                        }
                },
                    // {
                    //     field: 'productType',
                    //     title: '产品类型',
                        // formatter: function (value,row,index){
                        //     var reuslt = row.productType;
                        //     if (row.productType == 'DC'){
                        //         reuslt = '<span style="color: #1c84c6">贷超</span>';
                        //     }else if (row.productType == 'ZD'){
                        //         reuslt = '<span style="color: #f3124e">助贷</span>';
                        //     }
                        //     return reuslt;
                        // }
                    // },
                {
                    field: 'productLogo',
                    title: '产品Logo',
                    formatter: function (value,row,index){
                        return $.table.imageView(row.productLogo, 500, 500)
                    }
                },
                {
                    field: 'productPrice',
                    title: '产品价格'
                },
                {
                    field: 'sortWeight',
                    title: '排序权重'
                },
                    {
                        field: 'channelTypes',
                        title: '上架渠道类型'
                    },
                {
                    field: 'sceneIds',
                    title: '场景'
                },
                {
                    field: 'clientTypes',
                    title: '客户端'
                },
                // {
                //     field: 'notShowCitys',
                //     title: '不显示城市',
                //     formatter: function (value, row, index){
                //         var content = row.notShowCitys;
                //         if (content == undefined || content == ''){
                //             return '-';
                //         }
                //         return '<span style="color: darkgreen; border-bottom: 1px solid" onclick="showDetail(\''+content+'\')">展示</span>'
                //     }
                // },
                {
                    field: 'dayUvNumber',
                    title: '每日uv控量'
                },
                {
                    field: 'showStartTime',
                    title: '上架时间',
                    formatter: function (value, row, index){
                        return row.showStartTime + '~' + row.showEndTime;
                    }
                },
                // {
                //     field: 'showEndTime',
                //     title: '结束时间'
                // },
                {
                    field: 'showStartDate',
                    title: '上架日期',
                    formatter: function (value, row, index){
                        return row.showStartDate + '~' + row.showEndDate;
                    }
                },
                // {
                //     field: 'showEndDate',
                //     title: '结束日期'
                // },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);

        });


        /* 用户状态显示 */
        function statusTools(row) {
            if (row.status == 0) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
            }
        }

        /* 用户管理-停用 */
        function disable(id) {
            $.modal.confirm("确认要下架吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "id": id, "status": 0 });
            })
        }

        /* 用户管理启用 */
        function enable(id) {
            $.modal.confirm("确认要上架吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "id": id, "status": 1 });
            })
        }

        function showDetail(content){
            $.modal.alert(content,modal_status.MESSAGE, '渠道城市过滤信息');
        }
    </script>
</body>
</html>